<template>
  <el-dialog
    title="同济题库学习"
    :visible.sync="questionShow"
    width="60%"
    center
    :before-close="handleClose"
  >
    <!--<el-form ref="organizationReport" label-width="80px" label-position="right">
      <el-row>
        <el-col :span="8">
          <el-form-item label="政策">
            <div>{{ scheme.policyName }}</div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="行业">
            <div>{{ scheme.tradeName }}</div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="生产类型">
            <div>{{ scheme.enterpriseName }}</div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>-->
    <el-form label-width="80px" label-position="right">
      <el-row>
        <el-col :key="i" v-for="(list, i) in questionList.list">
          <h4>{{ (pagination.pageNo - 1) * 10 + i + 1 }}、({{list.in_name}}) {{ list.title }}</h4>
          <el-form-item style="margin-bottom: 0;">
            <div v-if="list.questionType === 0" style="margin: 10px 0;">
              <el-input type="textarea" :disabled="isEdit"></el-input>
            </div>
            <div v-else-if="list.questionType === 1">
              <div v-for="(item, i) in list.list" :key="i">
                <el-radio :label="item.content" :disabled="isEdit"></el-radio>
              </div>
            </div>
            <div v-else-if="list.questionType === 2">
              <div v-for="(item, i) in list.list" :key="i">
                <el-checkbox
                  :label="item.content"
                  name="type"
                  :disabled="isEdit"
                ></el-checkbox>
              </div>
            </div>
          </el-form-item>
        </el-col>
        <el-col>
          <el-pagination
            background
            layout="total, prev, pager, next, jumper"
            :page-size="pagination.pageSize"
            :total="pagination.total"
            @current-change="changeCurrent"
            @size-change="changePageSize"
          >
          </el-pagination>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleClose">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: [
    "questionShow",
    "questionData",
    "scheme",
    "isEdit",
    "itemArr",
    "isShow"
  ],
  name: "questionDialog",
  data() {
    return {
      pagination: {
        pageSize: 10,
        pageNo: 1,
        total: null
      },
      questionList: {}
    };
  },
  created() {
    this.pagination.pageNo = this.questionData.pageNumber;
    this.pagination.total = this.questionData.totalRow;
    this.questionList = this.questionData;
  },
  methods: {
    handleClose() {
      this.$emit("getDialogStatus");
    },
    //分页获取数据
    getPagetionData() {
      this.pagination.itemIds = this.itemArr;
      this.pagination.previewType = 0;
      this.pagination.schemeId = this.scheme.id;
      this.$post("/admin/scheme/previewItem", this.pagination).then(res => {
        this.pagination.pageNo = res.data.data.pageNumber;
        this.pagination.total = res.data.data.totalRow;
        this.questionList = res.data.data;
      });
    },
    //生成
    createScheme() {
      this.$post("/admin/scheme/previewItem", {
        itemIds: this.itemArr,
        schemeId: this.scheme.id,
        previewType: 1
      }).then(res => {
        if (res.data.state === "ok") {
          this.$message.success(res.data.message);
          this.$router.go(-1);
        } else {
          this.$message.error(res.data.message);
        }
      });
    },
    //分页
    //当前页事件
    changeCurrent(current) {
      this.pagination.pageNo = current;
      this.getPagetionData();
    },
    //分页改变事件
    changePageSize(pageSize) {
      this.getPagetionData();
      this.pagination.pageSize = pageSize;
    }
  }
};
</script>

<style scoped lang="scss">
.el-pagination {
  text-align: right;
  margin-top: 10px;
}
/deep/.el-radio {
  white-space: normal;
}
</style>
